<?php
/**
 * Created By Project
 * Author: 陈东
 * Copyright：陈东
 * Source Code：陈东
 * Explain：I shall not authorize for any other commercial purposes, law breakers must be prosecuted.
 */
namespace Admin\Controller;
use Think\Controller;
use Admin\Model\WfilmtypeModel;

class WfilmtypeController extends BaseController {

	protected function initobj(){
		return new WfilmtypeModel();
	}

	public function type(){
		$type = $this->initobj();
		$list = $this->getalllist($type);
		$this->assign('list',$list);
		$this->display('Wfilm/Wfilm_type');
	}

	//显示所有分类名称
	public function getalllist(){
		$type = $this->initobj();
		$res = $type->order('typesort asc')->select();
		return $res;
	}

	//添加
	public function add(){
		$type = $this->initobj();
		if(!$type->validate()->create()){
			$this->error($type->getError(),'',1);
		}else{
			$result = $type->add();
			if($result){
				$this->success('添加成功');
			}else{
				$this->error('添加失败','',1);
			}
		}
	}

	//删除
	public function delete($id = null){
		$type = $this->initobj();
		$res = $type->where(array('id'=>$id))->delete();
		if($res){
			$this->success('删除成功');
		}else{
			$this->error('删除失败','',1);
		}
	}

	//编辑输出
	public function edit($id = null){
		$type = $this->initobj();
		$res = $type->find($id);
		$this->assign('data',$res);
		$this->assign('edit',1);

		$list = $this->getalllist($type);
		$this->assign('list',$list);
		$this->display('Wfilm/Wfilm_type');
	}

	//保存
	public function sedit(){
		$type = $this->initobj();
		$id = I('post.editid');
		$rules = array(
			array('typename','require','分类不能为空！'),
		);
		if(!$type->validate($rules)->create()){
			$this->error($type->getError(),'',1);
		}else{
			$res = $type->where(array('id'=>$id))->save();
			if($res >= 0){
				$this->success('修改成功',U('type'));
			}else{
				$this->error('修改失败','',1);
			}
		}
	}



}